package com.abel.quiz.socket;/**
 * Created by abel.lin on 2017/11/7.
 */

import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import javax.annotation.Resource;

/**
 * @author abel.lin
 * @date_time 2017/11/7 14:32
 * @description
 */
@Component
@EnableWebSocket
public class WebSocketConfig extends WebMvcConfigurerAdapter implements WebSocketConfigurer {

    @Resource
    SystemWebSocketHandler handler;
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(handler, "/front/ws").addInterceptors(new WebSocketHandshakeInterceptor());
        registry.addHandler(handler, "/front/ws/sockjs").addInterceptors(new WebSocketHandshakeInterceptor()).withSockJS();
    }
}
